from django.db import models
from django.core import validators


class ArticleModel(models.Model):
    title = models.CharField(max_length=100)
    content = models.TextField()
    # thumbnail = models.FileField(upload_to='static')
    # TODO: 同时指定MEDIA_ROOT和upload_to，那么会将文件上传到MEDIA_ROOT下的upload_to文件夹中
    # thumbnail = models.FileField(upload_to='%Y-%m-%d/')

    # TODO: 【Django文件上传】限制上传的文件拓展名
    # thumbnail = models.FileField(upload_to='%Y-%m-%d/',
    #                              validators=[validators.FileExtensionValidator(['txt', 'text'], message='上传文件格式不符')])

    # TODO: 上传图片
    # ImageField会判断上传的文件是否是图片的格式（除了判断后缀名，还会判断是否是可用的图片）
    thumbnail = models.ImageField(upload_to='%Y-%m-%d/')
    create_time = models.DateTimeField(auto_now_add=True)

    class Meta:
        db_table = 'article'
